package com.esri.core.geometry;

import com.github.mikephil.charting.utils.Utils;

/* loaded from: classes.dex */
public class Transformation2D {
    public double xd;
    public double xx;
    public double xy;
    public double yd;
    public double yx;
    public double yy;

    void a(Point2D point2D, Point2D point2D2, double d) {
    }

    public Transformation2D() {
        setIdentity();
    }

    public Transformation2D(double d) {
        setScale(d);
    }

    public void setZero() {
        this.xx = Utils.DOUBLE_EPSILON;
        this.yy = Utils.DOUBLE_EPSILON;
        this.xy = Utils.DOUBLE_EPSILON;
        this.yx = Utils.DOUBLE_EPSILON;
        this.xd = Utils.DOUBLE_EPSILON;
        this.yd = Utils.DOUBLE_EPSILON;
    }

    public void a(Point2D point2D, Point2D point2D2) {
        point2D2.x = (this.xx * point2D.x) + (this.xy * point2D.y) + this.xd;
        point2D2.y = (this.yx * point2D.x) + (this.yy * point2D.y) + this.yd;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof Transformation2D) {
            Transformation2D transformation2D = (Transformation2D) obj;
            return this.xx == transformation2D.xx && this.xy == transformation2D.xy && this.xd == transformation2D.xd && this.yx == transformation2D.yx && this.yy == transformation2D.yy && this.yd == transformation2D.yd;
        }
        return false;
    }

    public int hashCode() {
        return NumberUtils.hash(NumberUtils.hash(NumberUtils.hash(NumberUtils.hash(NumberUtils.hash(NumberUtils.hash(this.xx), this.xy), this.xd), this.yx), this.yy), this.yd);
    }

    void a(Point2D[] point2DArr, int i, int i2) {
        int min = Math.min(point2DArr.length, i + i2);
        while (i2 < min) {
            a(point2DArr[i2], point2DArr[i2]);
            i2++;
        }
    }

    public void transform(Point[] pointArr, int i, Point[] pointArr2) {
        Point2D point2D = new Point2D();
        for (int i2 = 0; i2 < i; i2++) {
            Point2D a = pointArr[i2].a();
            point2D.x = (this.xx * a.x) + (this.xy * a.y) + this.xd;
            point2D.y = (this.yx * a.x) + (this.yy * a.y) + this.yd;
            pointArr2[i2] = new Point(point2D.x, point2D.y);
        }
    }

    public void transform(double[] dArr, int i, int i2) {
        int min = Math.min(dArr.length, (i + i2) * 2) / 2;
        while (i2 < min) {
            int i3 = i2 * 2;
            double d = dArr[i3];
            int i4 = i3 + 1;
            double d2 = dArr[i4];
            dArr[i3] = (this.xx * d) + (this.xy * d2) + this.xd;
            dArr[i4] = (this.yx * d) + (this.yy * d2) + this.yd;
            i2++;
        }
    }

    public void multiply(Transformation2D transformation2D) {
        multiply(this, transformation2D, this);
    }

    public void mulLeft(Transformation2D transformation2D) {
        multiply(transformation2D, this, this);
    }

    public static void multiply(Transformation2D transformation2D, Transformation2D transformation2D2, Transformation2D transformation2D3) {
        double d = transformation2D.xx;
        double d2 = transformation2D2.xx;
        double d3 = transformation2D.yx;
        double d4 = transformation2D2.xy;
        double d5 = (d * d2) + (d3 * d4);
        double d6 = transformation2D.xy;
        double d7 = transformation2D.yy;
        double d8 = transformation2D.xd;
        double d9 = d2 * d8;
        double d10 = transformation2D.yd;
        double d11 = d9 + (d4 * d10) + transformation2D2.xd;
        double d12 = transformation2D2.yx;
        double d13 = transformation2D2.yy;
        transformation2D3.xx = d5;
        transformation2D3.xy = (d6 * d2) + (d7 * d4);
        transformation2D3.xd = d11;
        transformation2D3.yx = (d * d12) + (d3 * d13);
        transformation2D3.yy = (d6 * d12) + (d7 * d13);
        transformation2D3.yd = (d8 * d12) + (d10 * d13) + transformation2D2.yd;
    }

    public Transformation2D copy() {
        Transformation2D transformation2D = new Transformation2D();
        transformation2D.xx = this.xx;
        transformation2D.xy = this.xy;
        transformation2D.xd = this.xd;
        transformation2D.yx = this.yx;
        transformation2D.yy = this.yy;
        transformation2D.yd = this.yd;
        return transformation2D;
    }

    public void getCoefficients(double[] dArr) {
        if (dArr.length < 6) {
            throw new GeometryException("Buffer is too small. coefs needs 6 members");
        }
        dArr[0] = this.xx;
        dArr[1] = this.xy;
        dArr[2] = this.xd;
        dArr[3] = this.yx;
        dArr[4] = this.yy;
        dArr[5] = this.yd;
    }

    public Envelope2D a(Envelope2D envelope2D) {
        if (envelope2D.isEmpty()) {
            return envelope2D;
        }
        Point2D[] point2DArr = new Point2D[4];
        envelope2D.queryCorners(point2DArr);
        a(point2DArr, point2DArr);
        envelope2D.setFromPoints(point2DArr, 4);
        return envelope2D;
    }

    void a(Point2D[] point2DArr, Point2D[] point2DArr2) {
        for (int i = 0; i < point2DArr.length; i++) {
            Point2D point2D = new Point2D();
            Point2D point2D2 = point2DArr[i];
            point2D.x = (this.xx * point2D2.x) + (this.xy * point2D2.y) + this.xd;
            point2D.y = (this.yx * point2D2.x) + (this.yy * point2D2.y) + this.yd;
            point2DArr2[i] = point2D;
        }
    }

    public void a(Envelope2D envelope2D, Envelope2D envelope2D2) {
        if (envelope2D.isEmpty() || envelope2D2.isEmpty() || Utils.DOUBLE_EPSILON == envelope2D.getWidth() || Utils.DOUBLE_EPSILON == envelope2D.getHeight()) {
            setZero();
            return;
        }
        this.yx = Utils.DOUBLE_EPSILON;
        this.xy = Utils.DOUBLE_EPSILON;
        this.xx = envelope2D2.getWidth() / envelope2D.getWidth();
        this.yy = envelope2D2.getHeight() / envelope2D.getHeight();
        this.xd = envelope2D2.xmin - (envelope2D.xmin * this.xx);
        this.yd = envelope2D2.ymin - (envelope2D.ymin * this.yy);
    }

    void b(Envelope2D envelope2D, Envelope2D envelope2D2) {
        if (envelope2D.isEmpty() || envelope2D2.isEmpty() || Utils.DOUBLE_EPSILON == envelope2D.getWidth() || Utils.DOUBLE_EPSILON == envelope2D.getHeight()) {
            setZero();
            return;
        }
        this.yx = Utils.DOUBLE_EPSILON;
        this.xy = Utils.DOUBLE_EPSILON;
        this.xx = envelope2D2.getWidth() / envelope2D.getWidth();
        double height = envelope2D2.getHeight() / envelope2D.getHeight();
        this.yy = height;
        double d = this.xx;
        if (d > height) {
            this.xx = height;
        } else {
            this.yy = d;
        }
        Point2D center = envelope2D2.getCenter();
        Point2D center2 = envelope2D.getCenter();
        this.xd = center.x - (center2.x * this.xx);
        this.yd = center.y - (center2.y * this.yy);
    }

    Point2D a(Point2D point2D) {
        Point2D point2D2 = new Point2D();
        double d = this.xx;
        double d2 = this.yx;
        point2D2.x = Math.sqrt((d * d) + (d2 * d2)) * point2D.x;
        double d3 = this.xy;
        double d4 = this.yy;
        point2D2.y = Math.sqrt((d3 * d3) + (d4 * d4)) * point2D.y;
        return point2D2;
    }

    public double transform(double d) {
        Point2D point2D = new Point2D();
        Point2D point2D2 = new Point2D();
        point2D.setCoords(this.xx, this.yx);
        point2D2.setCoords(this.xy, this.yy);
        point2D.sub(point2D);
        double a = point2D.a() * 0.5d;
        point2D.setCoords(this.xx, this.yx);
        point2D2.setCoords(this.xy, this.yy);
        point2D.add(point2D2);
        double a2 = point2D.a() * 0.5d;
        return d * (a > a2 ? Math.sqrt(a) : Math.sqrt(a2));
    }

    void a(Point2D[] point2DArr, int i, int i2, Point2D[] point2DArr2) {
        int i3 = i2 + i;
        while (i < i3) {
            Point2D point2D = point2DArr[i];
            point2DArr2[i].setCoords((this.xx * point2D.x) + (this.xy * point2D.y), (this.yx * point2D.x) + (this.yy * point2D.y));
            i++;
        }
    }

    Point2D b(Point2D point2D) {
        return Point2D.construct((this.xx * point2D.x) + (this.xy * point2D.y), (this.yx * point2D.x) + (this.yy * point2D.y));
    }

    public void setIdentity() {
        this.xx = 1.0d;
        this.xy = Utils.DOUBLE_EPSILON;
        this.xd = Utils.DOUBLE_EPSILON;
        this.yx = Utils.DOUBLE_EPSILON;
        this.yy = 1.0d;
        this.yd = Utils.DOUBLE_EPSILON;
    }

    public boolean isIdentity() {
        return this.xx == 1.0d && this.yy == 1.0d && Utils.DOUBLE_EPSILON == this.xy && Utils.DOUBLE_EPSILON == this.xd && Utils.DOUBLE_EPSILON == this.yx && Utils.DOUBLE_EPSILON == this.yd;
    }

    public boolean isIdentity(double d) {
        Point2D construct = Point2D.construct(Utils.DOUBLE_EPSILON, 1.0d);
        a(construct, construct);
        construct.sub(Point2D.construct(Utils.DOUBLE_EPSILON, 1.0d));
        double d2 = d * d;
        if (construct.a() > d2) {
            return false;
        }
        construct.setCoords(Utils.DOUBLE_EPSILON, Utils.DOUBLE_EPSILON);
        a(construct, construct);
        if (construct.a() > d2) {
            return false;
        }
        construct.setCoords(1.0d, Utils.DOUBLE_EPSILON);
        a(construct, construct);
        construct.sub(Point2D.construct(1.0d, Utils.DOUBLE_EPSILON));
        return construct.a() <= d2;
    }

    public boolean isReflective() {
        return (this.xx * this.yy) - (this.yx * this.xy) < Utils.DOUBLE_EPSILON;
    }

    public boolean isUniform(double d) {
        double d2 = this.xx;
        double d3 = this.yx;
        double d4 = (d2 * d2) + (d3 * d3);
        double d5 = this.xy;
        double d6 = this.yy;
        double d7 = (d5 * d5) + (d6 * d6);
        double d8 = (d4 + d7) * d;
        return Math.abs(d4 - d7) <= d8 && Math.abs((this.xx * this.xy) + (this.yx * this.yy)) <= d8;
    }

    public boolean isShift() {
        return this.xx == 1.0d && this.yy == 1.0d && Utils.DOUBLE_EPSILON == this.xy && Utils.DOUBLE_EPSILON == this.yx;
    }

    public boolean isShift(double d) {
        Point2D b = b(Point2D.construct(Utils.DOUBLE_EPSILON, 1.0d));
        b.y -= 1.0d;
        double d2 = d * d;
        if (b.a() > d2) {
            return false;
        }
        Point2D b2 = b(Point2D.construct(1.0d, Utils.DOUBLE_EPSILON));
        b2.x -= 1.0d;
        return b2.a() <= d2;
    }

    public boolean isOrthonormal(double d) {
        Transformation2D transformation2D = new Transformation2D();
        double d2 = this.xx;
        double d3 = this.xy;
        transformation2D.xx = (d2 * d2) + (d3 * d3);
        double d4 = this.xx;
        double d5 = this.yx;
        double d6 = this.yy;
        transformation2D.xy = (d4 * d5) + (d3 * d6);
        transformation2D.yx = (d5 * d4) + (this.xy * d6);
        double d7 = this.yx;
        transformation2D.yy = (d7 * d7) + (d6 * d6);
        transformation2D.xd = Utils.DOUBLE_EPSILON;
        transformation2D.yd = Utils.DOUBLE_EPSILON;
        return transformation2D.isIdentity(d);
    }

    public boolean isDegenerate(double d) {
        return Math.abs((this.xx * this.yy) - (this.yx * this.xy)) <= (d * 2.0d) * (Math.abs(this.xx * this.yy) + Math.abs(this.yx * this.xy));
    }

    public boolean isScaleAndShift(double d) {
        double d2 = this.xy;
        double d3 = this.yx;
        double d4 = (d2 * d2) + (d3 * d3);
        double d5 = this.xx;
        double d6 = this.yy;
        return d4 < ((d5 * d5) + (d6 * d6)) * d;
    }

    public void setShift(double d, double d2) {
        this.xx = 1.0d;
        this.xy = Utils.DOUBLE_EPSILON;
        this.xd = d;
        this.yx = Utils.DOUBLE_EPSILON;
        this.yy = 1.0d;
        this.yd = d2;
    }

    public void setScale(double d, double d2) {
        this.xx = d;
        this.xy = Utils.DOUBLE_EPSILON;
        this.xd = Utils.DOUBLE_EPSILON;
        this.yx = Utils.DOUBLE_EPSILON;
        this.yy = d2;
        this.yd = Utils.DOUBLE_EPSILON;
    }

    public void setScale(double d) {
        setScale(d, d);
    }

    public void setFlipX(double d, double d2) {
        this.xx = -1.0d;
        this.xy = Utils.DOUBLE_EPSILON;
        this.xd = d + d2;
        this.yx = Utils.DOUBLE_EPSILON;
        this.yy = 1.0d;
        this.yd = Utils.DOUBLE_EPSILON;
    }

    public void setFlipY(double d, double d2) {
        this.xx = 1.0d;
        this.xy = Utils.DOUBLE_EPSILON;
        this.xd = Utils.DOUBLE_EPSILON;
        this.yx = Utils.DOUBLE_EPSILON;
        this.yy = -1.0d;
        this.yd = d + d2;
    }

    public void setShear(double d, double d2) {
        this.xx = 1.0d;
        this.xy = d;
        this.xd = Utils.DOUBLE_EPSILON;
        this.yx = d2;
        this.yy = 1.0d;
        this.yd = Utils.DOUBLE_EPSILON;
    }

    public void setRotate(double d) {
        setRotate(Math.cos(d), Math.sin(d));
    }

    void a(double d, Point2D point2D) {
        a(Math.cos(d), Math.sin(d), point2D);
    }

    public void setRotate(double d, double d2) {
        this.xx = d;
        this.xy = -d2;
        this.xd = Utils.DOUBLE_EPSILON;
        this.yx = d2;
        this.yy = d;
        this.yd = Utils.DOUBLE_EPSILON;
    }

    void a(double d, double d2, Point2D point2D) {
        setShift(-point2D.x, -point2D.y);
        Transformation2D transformation2D = new Transformation2D();
        transformation2D.setRotate(d, d2);
        multiply(transformation2D);
        shift(point2D.x, point2D.y);
    }

    public void shift(double d, double d2) {
        this.xd += d;
        this.yd += d2;
    }

    public void scale(double d, double d2) {
        this.xx *= d;
        this.xy *= d;
        this.xd *= d;
        this.yx *= d2;
        this.yy *= d2;
        this.yd *= d2;
    }

    public void flipX(double d, double d2) {
        this.xx = -this.xx;
        this.xy = -this.xy;
        this.xd = (d + d2) - this.xd;
    }

    public void flipY(double d, double d2) {
        this.yx = -this.yx;
        this.yy = -this.yy;
        this.yd = (d + d2) - this.yd;
    }

    public void shear(double d, double d2) {
        Transformation2D transformation2D = new Transformation2D();
        transformation2D.setShear(d, d2);
        multiply(transformation2D);
    }

    public void rotate(double d) {
        Transformation2D transformation2D = new Transformation2D();
        transformation2D.setRotate(d);
        multiply(transformation2D);
    }

    public void rotate(double d, double d2) {
        Transformation2D transformation2D = new Transformation2D();
        transformation2D.setRotate(d, d2);
        multiply(transformation2D);
    }

    public void rotate(double d, double d2, Point point) {
        Transformation2D transformation2D = new Transformation2D();
        transformation2D.a(d, d2, point.a());
        multiply(transformation2D);
    }

    public void inverse(Transformation2D transformation2D) {
        double d = this.xx;
        double d2 = this.yy;
        double d3 = this.xy;
        double d4 = this.yx;
        double d5 = (d * d2) - (d3 * d4);
        if (d5 == Utils.DOUBLE_EPSILON) {
            transformation2D.setZero();
            return;
        }
        double d6 = 1.0d / d5;
        double d7 = this.yd;
        transformation2D.xd = ((d3 * d7) - (this.xd * d2)) * d6;
        transformation2D.yd = ((this.xd * d4) - (d * d7)) * d6;
        transformation2D.xx = d2 * d6;
        transformation2D.xy = (-d3) * d6;
        transformation2D.yx = (-d4) * d6;
        transformation2D.yy = this.xx * d6;
    }

    public void inverse() {
        inverse(this);
    }

    public void extractScaleTransform(Transformation2D transformation2D, Transformation2D transformation2D2) {
        double d = this.xx;
        double d2 = this.xy;
        double sqrt = Math.sqrt((d * d) + (d2 * d2));
        double d3 = this.yx;
        double d4 = this.yy;
        transformation2D.setScale(sqrt, Math.sqrt((d3 * d3) + (d4 * d4)));
        transformation2D2.setScale(1.0d / transformation2D.xx, 1.0d / transformation2D.yy);
        transformation2D2.multiply(this);
    }
}
